﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LoungeRepo.Contracts.Core;
using LoungeRepo.Core;

namespace Basics
{
    class Person : ILoungeRepoEntityIdentity
    {
        public Person() { this.Id = Guid.NewGuid().ToString(); }

        #region Implementation of ILoungeRepoEntityIdentity
        public string Id { get; set; }
        public string Partition { get { return "Persons"; } }
        #endregion

        public string Name { get; set; }
        public string City { get; set; }

        public Person Spouse { get; set; }

        public override string ToString()
        {
            return string.Format("{0} in {1}, {2}", 
                this.Name, 
                this.City,
                this.Spouse == null ? "single": "married");
        }
    }


    class Program
    {
        static void Main(string[] args)
        {
            using(ILoungeRepository repo = new LoungeRepository())
            {
                var her = new Person { Id = "1", Name = "Mary", City = "Boston" };
                var him = new Person { Id = "2", Name = "John", City = "Seattle", Spouse=her };
                her.Spouse = him;
                repo.Store(him);

                var p = repo.Load<Person>("2", "Persons");
                Console.WriteLine(p);
                Console.WriteLine(p.Spouse);


                him = new Person { Id = "3", Name = "Michael", City = "Dallas" };
                repo.Store(him);

                p = repo.Load<Person>("3", "Persons");
                Console.WriteLine(p);
            }
        }
    }
}
